/**
 * 用户经验相关接口类型定义
 */

import { BaseApiResponse } from "./interface";



// 经验类型枚举
export enum ExperienceType {
  SIGN_IN = 1,        // 签到经验
  TASK_COMPLETION = 2, // 任务完成
  LEVEL_UP_REWARD = 3, // 等级升级奖励
  ADMIN_ADJUSTMENT = 4, // 管理员调整
  ACTIVITY_REWARD = 5,  // 活动奖励
  CONSUMPTION = 6       // 消费扣除
}

// 操作来源枚举
export enum OperationSource {
  USER_ACTION = 1,    // 用户行为
  SYSTEM_AUTO = 2,    // 系统自动
  ADMIN_OPERATION = 3 // 管理员操作
}

// 经验统计按类型分组
export interface UserExperienceByType {
  signIn: number;        // 签到经验
  task: number;          // 任务完成经验
  levelUpReward: number; // 等级升级奖励经验
  admin: number;         // 管理员调整经验
  activity: number;      // 活动奖励经验
  consumption: number;   // 消费扣除经验
}

// 用户经验统计
export interface UserExperienceStats {
  totalExperience: number;           // 用户表中的总经验
  calculatedTotalExperience: number; // 通过经验记录计算的总经验
  experienceByType: UserExperienceByType; // 按类型分组的经验统计
  recentMonthExperience: number;     // 最近一个月获得的经验
  recentWeekExperience: number;      // 最近一周获得的经验
  todayExperience: number;           // 今天获得的经验
}

export interface UserExperienceStatsApiResponse extends BaseApiResponse<UserExperienceStats> {}

// 经验记录
export interface ExperienceRecord {
  id: string;
  userId: string;
  experienceChange: number;          // 经验变化量（正数为增加，负数为减少）
  experienceType: ExperienceType;    // 经验类型
  operationSource: OperationSource;  // 操作来源
  relatedId?: string;               // 关联的业务ID
  relatedType?: string;             // 关联的业务类型
  description?: string;             // 描述
  createTime: Date;                 // 创建时间
  operatorId?: string;              // 操作者ID
  extraData?: any;                  // 额外数据
}

// 经验记录列表响应
export interface ExperienceRecordsResponse {
  records: ExperienceRecord[];
  total: number;
  page: number;
  size: number;
  totalPages: number;
  summary: {
    totalGained: number;    // 总获得经验
    totalConsumed: number;  // 总消费经验
    netGained: number;      // 净获得经验
  };
}

export interface ExperienceRecordsApiResponse extends BaseApiResponse<ExperienceRecordsResponse> {}

// 同步用户经验响应
export interface SyncUserExperienceResponse {
  success: boolean;
  userId: string;
  oldExperience: number;
  newExperience: number;
  difference: number;
  syncedRecords: number;
  message?: string;
}

export interface SyncUserExperienceApiResponse extends BaseApiResponse<SyncUserExperienceResponse> {}

// 经验类型定义
export interface ExperienceTypeDefinition {
  type: ExperienceType;
  name: string;
  description: string;
}

// 操作来源定义
export interface OperationSourceDefinition {
  source: OperationSource;
  name: string;
  description: string;
}

// 经验类型说明响应
export interface ExperienceTypesResponse {
  experienceTypes: ExperienceTypeDefinition[];
  operationSources: OperationSourceDefinition[];
}

export interface ExperienceTypesApiResponse extends BaseApiResponse<ExperienceTypesResponse> {}
